package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.ServiceProvider;
import com.sky.result.Result;
import com.sky.service.ServiceProviderService;
import com.sky.vo.ServiceProviderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Set;

@RestController("userServiceProviderController")
@RequestMapping("/user/service-provider")
@Slf4j
@Api(tags = "C端-服务人员浏览接口")
public class ServiceProviderController {
    @Autowired
    private ServiceProviderService serviceProviderService;
    @Autowired
    private RedisTemplate redisTemplate;
    
    /**
     * 根据分类id查询服务人员
     *
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询服务人员")
    public Result<List<ServiceProviderVO>> list(Long categoryId) {
        String key = "service_provider_"+categoryId;
        List<ServiceProviderVO> list = (List<ServiceProviderVO>) redisTemplate.opsForValue().get(key);
        if (list != null && list.size() > 0){
            return Result.success(list);
        }

        ServiceProvider serviceProvider = new ServiceProvider();
        serviceProvider.setCategoryId(categoryId);
        serviceProvider.setStatus(StatusConstant.ENABLE);//查询启用中的服务人员

        list = serviceProviderService.listWithSkill(serviceProvider);
        redisTemplate.opsForValue().set(key,list);

        return Result.success(list);
    }

} 